define(["jquery", "easy-admin"], function ($, ea) {

    var init = {
        table_elem: '#currentTable',
        table_render_id: 'currentTableRenderId',
        index_url: 'store.seckill_config/index',
        add_url: 'store.seckill_config/add',
        edit_url: 'store.seckill_config/edit',
        delete_url: 'store.seckill_config/delete',
        export_url: 'store.seckill_config/export',
        modify_url: 'store.seckill_config/modify',
    };

    var Controller = {

        index: function () {
            ea.table.render({
                init: init,
                cols: [[
                    {type: 'checkbox'},
                    {field: 'id', search: false, title: 'id'},
                    {field: 'title', title: '秒杀名称'},
                    {
                        field: '#', search: false, title: '秒杀时间段', templet: function (res) {
                            let time1 = new Date(res.start_time*1000)
                            let year1 = time1.getFullYear()
                            let month1 = time1.getMonth() + 1
                            let date1 = time1.getDate()
                            let hours1 = time1.getHours()
                            let minute1 = time1.getMinutes()
                            let second1 = time1.getSeconds()

                            if (month1 < 10) {
                                month1 = '0' + month1
                            }
                            if (date1 < 10) {
                                date1 = '0' + date1
                            }
                            if (hours1 < 10) {
                                hours1 = '0' + hours1
                            }
                            if (minute1 < 10) {
                                minute1 = '0' + minute1
                            }
                            if (second1 < 10) {
                                second1 = '0' + second1
                            }
                            var start_time = year1 + '-' + month1 + '-' + date1 + ' ' + hours1 + ':' + minute1 + ':' + second1
                            let time2 = new Date(res.end_time*1000)
                            let year2 = time2.getFullYear()
                            let month2 = time2.getMonth() + 1
                            let date2 = time2.getDate()
                            let hours2 = time2.getHours()
                            let minute2 = time2.getMinutes()
                            let second2 = time2.getSeconds()

                            if (month2 < 10) {
                                month2 = '0' + month2
                            }
                            if (date2 < 10) {
                                date2 = '0' + date2
                            }
                            if (hours2 < 10) {
                                hours2 = '0' + hours2
                            }
                            if (minute2 < 10) {
                                minute2 = '0' + minute2
                            }
                            if (second2 < 10) {
                                second2 = '0' + second2
                            }
                            var end_time = year2 + '-' + month2 + '-' + date2 + ' ' + hours2 + ':' + minute2 + ':' + second2
                            return start_time + "-" + end_time

                        }
                    },
                    {field: 'image', search: false, title: '幻灯片', templet: ea.table.image},
                    {
                        field: 'status',
                        title: '状态',
                        width: 85,
                        search: 'select',
                        selectList: {0: '隐藏', 1: '显示'},
                        filter: 'status',
                        templet: ea.table.switch
                    },
                    {width: 250, title: '操作', templet: ea.table.tool},
                ]],
            });

            ea.listen();
        },
        add: function () {
            ea.listen();
        },
        edit: function () {
            ea.listen();
        },

    };
    return Controller;
});